package cn.com.recycleviewdemo.decoration;

import android.content.Context;
import android.graphics.Rect;
import android.support.annotation.DimenRes;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

/**
 * 作者: 鹿文龙
 * 时间: 2017/11/17
 */

public class ItemOffsetDecoration2 extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration2(int itemOffset) {
        mItemOffset = itemOffset;
    }

    public ItemOffsetDecoration2(@NonNull Context context, @DimenRes int itemOffsetId) {
        this(context.getResources().getDimensionPixelSize(itemOffsetId));
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        int position = parent.getChildAdapterPosition(view);
        int pos = position;
        if (position == 0) {
            outRect.set(0, 0, 0, 0);
            return;
        }

        outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset);

    }
}

